<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <j-input placeholder="请输入姓名" v-model="queryParam.name"></j-input>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属部门">
              <j-search-select-tag placeholder="请选择所属部门" v-model="queryParam.departmentId"
                                   dict="sys_depart,depart_name,id"/>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属部门">
              <j-select-depart :disabled=false v-model="queryParam.departmentId"/>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="职务级别">
              <j-dict-select-tag
                placeholder="请选择职务级别"
                v-model="queryParam.positionLevelId"
                dictCode="erp_org_position_level,level_name,id,del_flag='0' and audit_status='2'" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="人员状态">
                <j-dict-select-tag placeholder="请选择人员状态" style="radio" v-model="queryParam.employeeStatus"
                  dictCode="employee_status" />
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="人员类型">
                <j-dict-select-tag placeholder="请选择人员类型" v-model="queryParam.employeeType" dictCode="employee_type" />
              </a-form-item>
            </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            <!-- <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span> -->
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpEmployeeFileResign:add')">新增
      </a-button> -->
      <a-button
        type="primary"
        icon="download"
        @click="handleExport">导出
      </a-button>
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpEmployeeFileResign:import')">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <!-- <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpEmployeeFileResign:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item> -->
          <a-menu-item key="2" @click="batchSubmit" v-has="'erpEmployeeFileResign:submit'">
            <a-icon type="to-top" />
            提交
          </a-menu-item>
          <a-menu-item key="3" @click="batchAudit" v-has="'erpEmployeeFileResign:audit'">
            <a-icon type="audit" />
            审核
          </a-menu-item>
          <a-menu-item key="4" @click="batchCounterTrial" v-has="'erpEmployeeFileResign:counterTrial'">
            <a-icon type="rollback" />
            反审
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle" />
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        :customRow="handleCustomRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="link" slot-scope="text, record">
          <a @click.stop="handleclick(record)">{{ text }}</a>
        </span>
        <span slot="action" slot-scope="text, record">

          <template v-if="record.auditStatus == 0">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              v-has="'erpEmployeeFileResign:edit'"/>
            <!-- <a-divider type="vertical"/>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" :disabled="isDisabledAuth('erpEmployeeFileResign:delete')">
                  <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="delete"
                    :disabled="isDisabledAuth('erpEmployeeFileResign:delete')"/>
              </a-popconfirm> -->
            <a-divider type="vertical" />
            <a-popconfirm
              title="确定提交吗?"
              @confirm="() => handleSubmit(record.id)"
              v-has="'erpEmployeeFileResign:submit'">
              <a-button type="primary" size="small" v-has="'erpEmployeeFileResign:submit'">提交</a-button>
            </a-popconfirm>

          </template>
          <span v-has="'erpEmployeeFileResign:audit'">
            <a-button
              type="primary"
              size="small"
              @click="handleAudit(record.id)"
              v-if="record.auditStatus == 1"
            >审核</a-button>
          </span>
          <span v-has="'erpEmployeeFileResign:counterTrial'">
            <a-popconfirm
              title="确定反审吗?"
              @confirm="() => handleCounterTrial(record.id)"
              v-if="record.auditStatus == 2"
            >
              <a-button
                type="primary"
                size="small"
                v-if="record.auditStatus == 2">反审</a-button>
            </a-popconfirm>
          </span>
          <span v-has="'erpEmployeeFileResign:contract'">
            <a-divider type="vertical" />
            <a-popconfirm
              title="确定新增合同吗?"
              @confirm="() => handleContract(record)"
              v-if="record.auditStatus == 2">
              <a-button type="primary" size="small" v-if="record.auditStatus == 2">合同</a-button>
            </a-popconfirm>
          </span>
          <!--
          <template v-if="record.auditStatus==2">
            <a-divider type="vertical"/>
              <a-popconfirm title="确定新增入职申请吗?" @confirm="() => handleRegular(record)">
                  <a-button type="primary" size="small"
                            :disabled="isDisabledAuth('erpEmployeeFileResign:counterTrial')">转正申请</a-button>
              </a-popconfirm>
          </template>
          <template v-if="record.auditStatus==2">
            <a-divider type="vertical"/>
              <a-popconfirm title="确定新增调岗调薪申请吗?" @confirm="() => handleAdjust(record)">
                  <a-button type="primary" size="small"
                            :disabled="isDisabledAuth('erpEmployeeFileResign:counterTrial')">调岗调薪</a-button>
              </a-popconfirm>
          </template>
          <template v-if="record.auditStatus==2">
            <a-divider type="vertical"/>
              <a-popconfirm title="确定新增离职申请吗?" @confirm="() => handleResign(record)">
                  <a-button type="primary" size="small"
                            :disabled="isDisabledAuth('erpEmployeeFileResign:counterTrial')">离职</a-button>
              </a-popconfirm>
          </template> -->
        </span>

      </a-table>
    </div>
    <erp-hr-employee-contract-modal ref="contractForm" @ok="modalFormOk"></erp-hr-employee-contract-modal>
    <!-- <erp-hr-employee-resign-bill-modal ref="resignForm" @ok="modalFormOk"></erp-hr-employee-resign-bill-modal>
    <erp-hr-post-salary-adjustment-modal ref="adjustForm" @ok="modalFormOk"></erp-hr-post-salary-adjustment-modal>
    <erp-hr-employee-regular-bill-modal ref="regularForm" @ok="modalFormOk"></erp-hr-employee-regular-bill-modal> -->
    <erp-employee-file-modal ref="modalForm" @ok="modalFormOk"></erp-employee-file-modal>
    <employee-transfer ref="exportMenu" @ok="exportOk"></employee-transfer>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpEmployeeFileModal from './modules/ErpEmployeeFileModal'
import EmployeeTransfer from './modules/EmployeeTransfer'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import ErpHrEmployeeContractModal from '@/views/erp/hr/contract/modules/ErpHrEmployeeContractModal'
// import ErpHrEmployeeRegularBillModal from '@/views/erp/hr/regular/modules/ErpHrEmployeeRegularBillModal'
// import ErpHrPostSalaryAdjustmentModal from '@/views/erp/hr/adjust/modules/ErpHrPostSalaryAdjustmentModal'
// import ErpHrEmployeeResignBillModal from '@/views/erp/hr/resign/modules/ErpHrEmployeeResignBillModal'
import { downFile } from '@/api/manage'

export default {
  name: 'ErpEmployeeFileDepartList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpEmployeeFileModal,
    ErpHrEmployeeContractModal,
    EmployeeTransfer
    // ErpHrEmployeeRegularBillModal,
    // ErpHrPostSalaryAdjustmentModal,
    // ErpHrEmployeeResignBillModal
  },
  data() {
    return {
      description: '员工档案管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '人员编号',
          align: 'center',
          width: 200,
          ellipsis: true,
          dataIndex: 'employeeNo'
        },
        {
          title: '姓名',
          align: 'center',
          width: 100,
          dataIndex: 'name',
          ellipsis: true,
          scopedSlots: {
            customRender: 'link'
          }
        },
        // {
        //   title: '所属部门',
        //   align: 'center',
        //   dataIndex: 'departmentId_dictText',
        // },
        /* {
          title:'所属部门编码',
          align:"center",
          dataIndex: 'departmentCode_dictText',
        }, */
        // {
        //   title: '职务级别',
        //   align: 'center',
        //   width: 200,
        //   dataIndex: 'positionLevelId_dictText'
        // },
        {
          title: '所属团队',
          width: 300,
          ellipsis: true,
          align: 'center',
          dataIndex: 'team'
        },
        {
          title: '岗位',
          align: 'center',
          width: 300,
          ellipsis: true,
          dataIndex: 'post'
        },
        // {
        //   title: '人员类型',
        //   align: 'center',
        //   dataIndex: 'employeeType_dictText',
        // },
        // {
        //   title: '人员状态',
        //   align: 'center',
        //   dataIndex: 'employeeStatus_dictText',
        // },
        /* {
           title:'是否已删除',
           align:"center",
           dataIndex: 'delFlag_dictText',
         }, */
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'auditStatus_dictText',
          scopedSlots: { customRender: 'status' },
          filterMultiple: false,
          filters: [
            {
              text: '待提交',
              value: 0
            }, {
              text: '待审核',
              value: 1
            }, {
              text: '已审核',
              value: 2
            }]
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 160,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        // list: '/api/erp/files/employee/erpEmployeeFile/list',
        list: '/api/erp/files/newEmployee/erpNewEmployeeFile/resignList?employeeStatus=2',
        delete: '/api/erp/files/employee/erpEmployeeFile/delete',
        deleteBatch: '/api/erp/files/employee/erpEmployeeFile/deleteBatch',
        exportXlsUrl: '/api/erp/files/employee/erpEmployeeFile/resignExportXls',
        importExcelUrl: 'api/erp/files/employee/erpEmployeeFile/importExcel',
        submit: '/api/erp/files/employee/erpEmployeeFile/submit',
        submitBatch: '/api/erp/files/employee/erpEmployeeFile/submitBatch',
        revoke: '/api/erp/files/employee/erpEmployeeFile/revoke',
        revokeBatch: '/api/erp/files/employee/erpEmployeeFile/revokeBatch',
        counterTrial: '/api/erp/files/employee/erpEmployeeFile/counterTrial',
        counterTrialBatch: '/api/erp/files/employee/erpEmployeeFile/counterTrialBatch',
        audit: '/api/erp/files/employee/erpEmployeeFile/audit',
        auditBatch: '/api/erp/files/employee/erpEmployeeFile/auditBatch',
        overrule: '/api/erp/files/employee/erpEmployeeFile/overrule',
        overruleBatch: '/api/erp/files/employee/erpEmployeeFile/overruleBatch'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    handleExport() {
      this.$refs.exportMenu.visible = true
      this.$refs.exportMenu.getOptions()
    },
    exportOk(val) {
      const fileName = '员工档案'
      let param = this.getQueryParams()
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      param.map = val
      param.employeeStatus = '2'
      console.log('导出参数', param)
      downFile(this.url.exportXlsUrl, param).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            }),
            fileName + '.xls'
          )
        } else {
          let url = window.URL.createObjectURL(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            })
          )
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },
    handleclick(record) {
      this.$router.push({
        path: '/schedule',
        query: {
          id: record.id,
          applyId: record.applyId
        }
      })
    },
    handleCustomRow(record) {
      return {
        on: {
          // 事件
          dblclick: event => {
            this.$router.push({
              path: '/schedule',
              query: {
                id: record.id,
                applyId: record.applyId
              }
            })
          }
        }
      }
    },
    // handleResign(record){
    //   this.$refs.resignForm.add(record);
    // },
    // handleAdjust(record){
    //   this.$refs.adjustForm.add(record);
    // },
    handleContract(record) {
      this.$refs.contractForm.add(record);
    },
    // handleRegular(record){
    //   this.$refs.regularForm.add(record);
    // },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'name', text: '姓名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'photo', text: '照片', dictCode: '' })
      fieldList.push({ type: 'string', value: 'gender', text: '性别', dictCode: 'gender' })
      fieldList.push({ type: 'string', value: 'national', text: '民族', dictCode: '' })
      fieldList.push({ type: 'string', value: 'nativePlace', text: '籍贯', dictCode: '' })
      fieldList.push({ type: 'string', value: 'growUpPlace', text: '成长地', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bloodType', text: '血型', dictCode: 'blood_type' })
      fieldList.push({ type: 'string', value: 'usedName', text: '曾用名', dictCode: '' })
      fieldList.push({ type: 'date', value: 'birthDate', text: '出生日期' })
      fieldList.push({ type: 'string', value: 'idCardNo', text: '身份证号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'accountStatus', text: '账户状态', dictCode: 'ENABLE_OR_DISABLE' })
      fieldList.push({ type: 'string', value: 'firstLanguage', text: '首选语言', dictCode: 'first_language' })
      fieldList.push({ type: 'Text', value: 'hobby', text: '业余爱好', dictCode: '' })
      fieldList.push({ type: 'int', value: 'sortNo', text: '人员排序号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'employeeNo', text: '人员编号', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'departmentId',
        text: '所属部门',
        dictTable: 'sys_depart',
        dictText: 'depart_name',
        dictCode: 'id'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'departmentCode',
        text: '所属部门编码',
        dictTable: 'sys_depart',
        dictText: 'depart_name',
        dictCode: 'org_code'
      })
      fieldList.push({
        type: 'string',
        value: 'positionLevelId',
        text: '职务级别',
        dictCode: 'erp_org_position_level,level_name,id'
      })
      fieldList.push({ type: 'string', value: 'mainPost', text: '主岗', dictCode: 'sys_position,name,id' })
      fieldList.push({ type: 'string', value: 'deputyPost', text: '副岗', dictCode: 'sys_position,name,id' })
      fieldList.push({ type: 'string', value: 'employeeType', text: '人员类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'employeeStatus', text: '人员状态', dictCode: 'employee_status' })
      fieldList.push({ type: 'string', value: 'workplace', text: '工作地', dictCode: '' })
      fieldList.push({ type: 'string', value: 'directLeadership', text: '汇报人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'major', text: '专业', dictCode: '' })
      fieldList.push({ type: 'date', value: 'joinDate', text: '入职时间' })
      fieldList.push({ type: 'date', value: 'beginWorkDate', text: '参加工作时间' })
      fieldList.push({ type: 'BigDecimal', value: 'fileSalary', text: '档案工资', dictCode: '' })
      fieldList.push({ type: 'string', value: 'highestDegree', text: '最高学历', dictCode: 'degree' })
      fieldList.push({ type: 'string', value: 'politicalLandscape', text: '政治面貌', dictCode: 'political_landscape' })
      fieldList.push({ type: 'string', value: 'maritalStatus', text: '婚姻状况', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attachment', text: '附件', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'delFlag', text: '是否已删除', dictCode: 'del_flag' })
      fieldList.push({ type: 'string', value: 'auditStatus', text: '审核状态', dictCode: 'audit_status' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
